﻿var hasLogin = false; //登录状态
//判断是否登录
isLogin();

//获取用户信息
function getUserInfo() {
    var url = "Handler.ashx";
    var pars = "act=GetUserInfo";
    Ajax(url, pars, "get", getUserInfo_Complete, getUserInfo_Wait, true);
    url = null;
    pars = null;
}

function getUserInfo_Complete(req) {
    if (req.responseText.length>6) {
        $("userinfo").innerHTML = "&nbsp;<b>操作员</b>：" + req.responseText.split(",")[0] + "&nbsp;&nbsp;<b>院系</b>：" + req.responseText.split(",")[1] + "&nbsp;&nbsp;<b>科室</b>：" + req.responseText.split(",")[2] + "&nbsp;&nbsp;<b>角色</b>：" + req.responseText.split(",")[3] + "&nbsp;&nbsp;<b>级别</b>：" + req.responseText.split(",")[4] + "&nbsp;&nbsp;<b>登录次数</b>：" + req.responseText.split(",")[5] + "次&nbsp;&nbsp;<b>上次登录</b>：" + req.responseText.split(",")[6];
    }
}

function getUserInfo_Wait() {

}

//设置用户一级权限
function setRank() {
    var rank = unescape(getCookie("u_rank"));
    var ranklist = rank.split("|");
    for (var i = 0; i < ranklist.length; i++) {
        if (ranklist[i].split(",")[1] == "首页") {
            $("m1").style.display = "block";
            $("m1").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"首 页\");hilight(this);'>首 页</a>";
            getChildRank(ranklist[i].split(",")[0], "首 页");
        }
        else if (ranklist[i].split(",")[1] == "科研项目") {
            $("m2").style.display = "block";
            $("m2").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"科研项目\");hilight(this);'>科研项目</a>";
        }
        else if (ranklist[i].split(",")[1] == "科研成果") {
            $("m3").style.display = "block";
            $("m3").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"科研成果\");hilight(this);'>科研成果</a>";
        }
        else if (ranklist[i].split(",")[1] == "学术活动") {
            $("m4").style.display = "block";
            $("m4").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"学术活动\");hilight(this);'>学术活动</a>";
        }
        else if (ranklist[i].split(",")[1] == "刊物管理") {
            $("m5").style.display = "block";
            $("m5").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"刊物管理\");hilight(this);'>刊物管理</a>";
        }
        else if (ranklist[i].split(",")[1] == "机构管理") {
            $("m6").style.display = "block";
            $("m6").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"机构管理\");hilight(this);'>机构管理</a>";
        }
        else if (ranklist[i].split(",")[1] == "人员管理") {
            $("m7").style.display = "block";
            $("m7").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"人员管理\");hilight(this);'>人员管理</a>";
        }
        else if (ranklist[i].split(",")[1] == "量化考核") {
            $("m8").style.display = "block";
            $("m8").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"量化考核\");hilight(this);'>量化考核</a>";
        }
        else if (ranklist[i].split(",")[1] == "科研统计") {
            $("m9").style.display = "block";
            $("m9").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"科研统计\");hilight(this);'>科研统计</a>";
        }
        else if (ranklist[i].split(",")[1] == "综合报表") {
            $("m10").style.display = "block";
            $("m10").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"综合报表\");hilight(this);'>综合报表</a>";
        }
//        else if (ranklist[i].split(",")[1] == "质量工程") {
//            $("m11").style.display = "block";
//            $("m11").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"质量工程\");hilight(this);'>质量工程</a>";
//        }
//        else if (ranklist[i].split(",")[1] == "其他申报") {
//            $("m12").style.display = "block";
//            $("m12").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"其他申报\");hilight(this);'>其他申报</a>";
//        }
        else if (ranklist[i].split(",")[1] == "系统管理") {
            $("m12").style.display = "block";
            $("m12").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"系统管理\");hilight(this);'>系统管理</a>";
        }
//        else if (ranklist[i].split(",")[1] == "教研项目") {
//            $("m13").style.display = "block";
//            $("m13").innerHTML = "<a href='#' onfocus='this.blur()' onclick='getChildRank(" + ranklist[i].split(",")[0] + ",\"教研项目\");hilight(this);'>教研项目</a>";
//        }
        
    }
}

//获取子权限
function getChildRank(index,str) {
    $("LeftMenu").src = "Menu/M.htm?pid=" + index;
    $("navigation1").innerHTML = str;
    $("navigation2").innerHTML = "";
    $("navigation3").innerHTML = "";
    //设置主框架页面
    if (str == "首 页") {
        window.frames["main"].location.href = "Notice/Notice_Main.aspx";
        //$("main").src = "Main/main.aspx";
    }
    else if (str == "科研项目") {
        window.frames["main"].location.href = "Items/Items_List.aspx";
    }
    else if (str == "科研成果") {
        window.frames["main"].location.href = "Results/Thesis_List.aspx";
    }
    else if (str == "刊物管理") {
        window.frames["main"].location.href = "Publication/Publication_List.aspx";
    }
    else if (str == "机构管理") {
        window.frames["main"].location.href = "Institution/Unit_List.aspx";
    }
    else if (str == "人员管理") {
        window.frames["main"].location.href = "Personnel/Personnel_List.aspx";
    }
    else if (str == "学术活动") {
        window.frames["main"].location.href = "Activity/MainMeeting_List.aspx";
    }
    else if (str == "科研统计") {
        window.frames["main"].location.href = "Statis/Statis_List.aspx";
    }
    else if (str == "教研项目") {
        window.frames["main"].location.href = "Faculty/Items_List.aspx";
    }
    else if (str == "综合报表") {
        window.frames["main"].location.href = "Research/Items_ReportSearch.aspx";
    }
    else if (str == "质量工程") {
        window.frames["main"].location.href = "Teach/Items_List.aspx";
    }
    else if(str == "量化考核"){
        window.frames["main"].location.href = "Score/Items_BatchList.aspx";
    }
    else if(str == "系统管理"){
        window.frames["main"].location.href = "Base/Quantitative_List.aspx";
    }
}

//退出登录
function exit() {
    if (confirm("您确定要退出系统吗？")) {
        loginOut();
    }
}

//请求退出登录
function loginOut() {
    var url = "Handler.ashx";
    var pars = "act=LoginOut";
    Ajax(url, pars, "get", loginOut_Complete, loginOut_Wait, true);
    url = null;
    pars = null;
}

function loginOut_Complete(req) {
    if (req.responseText == "true") {
        window.location = "index.html";
    }
    else {
        //强制关闭
        window.opener = null; //如果后面需要用openner，这一行可以去掉 
        window.open('', '_top');
        window.top.close();
    }
}

function loginOut_Wait() {

}

//判断登录
function isLogin() {
    var url = "Handler.ashx";
    var pars = "act=IsLogin";
    Ajax(url, pars, "get", isLogin_Complete, isLogin_Wait, true);
    url = null;
    pars = null;
}

function isLogin_Complete(req) {
    if (req.responseText != "true") {
        hasLogin = false;
        window.location = "index.html";
    }
    else {
        hasLogin = true;
    }
}

function isLogin_Wait() {

}

window.onload = function() {
    if (hasLogin) {
        //调整页面高度
        setIFrameHx();
        //设置权限
        setRank();
        //顶部导航
        subTab("navTop");
        //获取用户信息
        getUserInfo();
        $("navigation1").innerHTML = "首 页";
    }
}
